#include<stdio.h>
#include<unistd.h>
#include<errno.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

#define filename "bite"
int main()
{
  //系统调用文件
  /*
  int fd=open(filename,O_RDWR|O_CREAT|O_TRUNC,0666);
  const char *msg = "i like linux!";
  int cnt = 1;
  
  while(cnt)
  {
      char line[128];
    snprintf(line, sizeof(line), "%s\n", msg);

      write(fd, line, strlen(line)); 
      cnt--;
  }
  lseek(fd,0,SEEK_SET);
  char buffer[1024];
  ssize_t n = read(fd, buffer, sizeof(buffer)-1);
  if(n > 0)
  {
    buffer[n] = '\0';
    printf("%s\n", buffer);
  }

  close(fd);
  */

  //C文件操作
  FILE* fp;
  const char* str="linux so easy!";
  char readstr[128]={'\0'};
  fp=fopen(filename,"w+");
  fwrite(str,sizeof(char),strlen(str),fp);
  fseek(fp,0,SEEK_SET);
  fread(readstr,sizeof(char),strlen(str),fp);
  printf("%s",readstr);
  fclose(fp);
  return 0;
}
